'use strict';
const dayjs = require("dayjs");
const {getDefaultModelConfig} = require("../../utils/common");

module.exports = app => {
    const { STRING, INTEGER, DATE, TINYINT } = app.Sequelize;
    const Collection = app.model.define(
        'Collection',
        {
            id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            product_id: INTEGER,
            user_id: INTEGER,
            status: {type: TINYINT, defaultValue: 1},
            ...getDefaultModelConfig(app)
        },
        {
            tableName: 'collection',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );
    Collection.associate = function () {
        app.model.Business.Collection.belongsTo(app.model.Business.Product, { foreignKey: 'product_id', as: 'product' });
        app.model.Business.Collection.belongsTo(app.model.Business.User, { foreignKey: 'user_id', as: 'user' });
    }


    return Collection
};
